﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;


namespace Book
{
    public partial class Form5_3 : Form
    {
        public Form5_3()
        {
            InitializeComponent();
        }

        private void 查看单本书籍_Click(object sender, EventArgs e)
        {
            OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
            string sql = "select * from book where 书号='" + textBox1.Text + "'";
            OleDbDataAdapter thisAdapter = new OleDbDataAdapter(sql, thisConnection);
            System.Data.DataSet thisDataSet = new System.Data.DataSet();
            thisAdapter.Fill(thisDataSet, "table");
            DataTable dt = thisDataSet.Tables["table"];
            this.dataGridView1.DataSource = dt;
            thisConnection.Close();
        }

        private void 查看全部书籍信息_Click(object sender, EventArgs e)
        {
            OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
            string sql = "select * from book";
            OleDbDataAdapter thisAdapter = new OleDbDataAdapter(sql, thisConnection);
            System.Data.DataSet thisDataSet = new System.Data.DataSet();
            thisAdapter.Fill(thisDataSet, "table");
            DataTable dt = thisDataSet.Tables["table"];
            this.dataGridView1.DataSource = dt;
            thisConnection.Close();
        }

        private void 删除书籍_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定删除此书籍吗？", "提示", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                OleDbConnection DBconnect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
                DBconnect.Open();
                string sql = string.Format("delete from book where 书号='{0}'", textBox2.Text);             //删除执行             
                OleDbCommand oleDbCommand = new OleDbCommand(sql, DBconnect);
                int i = oleDbCommand.ExecuteNonQuery();
                MessageBox.Show("删除成功！");
            }
            if (result == DialogResult.Cancel)
            {
            }
        }

        private void Form5_3_Load(object sender, EventArgs e)
        {
            label3.Text = string.Format("管理员：{0}", UserHelper.UserName);
            timer1.Start();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.Show();
            this.Close();
        }

        private void 添加图书ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5_2 form5_2 = new Form5_2();
            form5_2.Show();
        }

        private void 查看删除图书ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5_3 form5_3 = new Form5_3();
            form5_3.Show();
        }

        private void 查看删除读者ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5_1 form5_1 = new Form5_1();
            form5_1.Show();
        }

        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4_4 form4_4 = new Form4_4();
            form4_4.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label4.Text = DateTime.Now.ToString(); 
        }
    }
}
